package com.tanhua.dubbo.server.service;

import com.tanhua.dubbo.server.enums.IdType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class IdService {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;
    //实现的逻辑：借助Redis自动增长的特性，实现全局的ID自增长(唯一)
    public Long CreateId(IdType idType){
        String key="TANHUA_ID_" + idType.toString();
        return this.redisTemplate.opsForValue().increment(key);
    }

}
